﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace lib
{
        // @Author Jens Uuldriks 
        [Serializable()]
        public class TestResult
        {
            List<MeasuredValues> list = new List<MeasuredValues>();
            public String Behandelaar { get; set; }
            public String Patientnr { get; set; }
            public String Patientnaam { get; set; }
            public DateTime Tijd { get; set; }

            public TestResult()
            {

            }

            public TestResult(String s)
            {
                System.Diagnostics.Debug.WriteLine(s);
                string[] testResults = s.Split('/');
                Behandelaar = testResults[0];
                Patientnr = testResults[1];
                Patientnaam = testResults[2];
                string[] date = testResults[3].Split('-');
                Tijd = new DateTime(Convert.ToInt32(date[2].Substring(0,4)), Convert.ToInt32(date[1]), Convert.ToInt32(date[0]));
                string[] metingen = testResults[4].Split(';');
                foreach (string value in metingen)
                {
                   list.Add(new MeasuredValues(value));
                }


            }

            public void AddMeasuredValues(MeasuredValues m)
            {
                list.Add(m);
            }

            public MeasuredValues getLast()
            {
                return list.Last();
            }

            public List<MeasuredValues> GetMeasuredValues()
            {
                return list;
            }

            public void SetNaam(String s)
            {
                Patientnaam = s;
            }

            public void SetNr(String s)
            {
                Patientnr = s;
            }

            public string Getnaam()
            {
                return Patientnaam;
            }

            public string Getnr()
            {
                return Patientnr;
            }

            public String getString()
            {
                string Metingen = "";
                foreach (MeasuredValues item in list)
                {
                    if(Metingen.Equals("")) Metingen = item.getString();
                    else
                    {
                        Metingen = Metingen + ";" + item.getString() ;
                    }
                }
                string result = Behandelaar + "/" + Patientnr + "/" + Patientnaam + "/" + Tijd.ToString().Replace(":", "") + "/" + Metingen;
                System.Diagnostics.Debug.WriteLine("Result " + result);
                return result;
            }
        }
    }

